package com.baking.controller;

import com.baking.model.Product;
import com.baking.service.ProductSerice;
import com.baking.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:wrb
 * @Date :2020/1/10/9:10
 * @Describtion:测试用的页面
 **/
@Controller
@RequestMapping("/test")
public class TestController {


    @Autowired
    ProductSerice productSerice;

    @RequestMapping("/getProductList_v1")
    @ResponseBody
    public Msg getProductList_v1(@RequestParam(value = "productName",required = false) String productName,
                                 @RequestParam (value="page") String pageno,
                                 @RequestParam (value="limit") String pagesize){
        System.out.println("productName = [" + productName + "], pageno = [" + pageno + "], pagesize = [" + pagesize + "]");
        Msg msg = new Msg();
        Product product = new Product();
        product.setProductName(productName);
        List<Product> productList = productSerice.getProductList(product);
        msg.setCode("0");
        msg.setData(productList);
        return msg;
    }

    /** @Description:
     * 用@RequestBody时，要在前端把该数据转成json格式，
     * 即转成JSON.stringify(param)传进来
     * @Author:wrb
     * @Date:2020/1/10/17:25
     * @Param 
     * @return com.baking.util.Msg
     */
    @RequestMapping(value = "/getProductList_v2",method=RequestMethod.POST,produces = "application/json; utf-8")
    @ResponseBody
    public Msg getProductList_v2(@RequestBody Product product){
        Msg msg = new Msg();
        System.out.println("getProductList_v2==>"+product);
        List<Product> productList = productSerice.getProductList(product);
        msg.setCode("0");
        msg.setData(productList);
        return msg;
    }
    /** @Description: 或者下面这种方式
     * 用@RequestBody时，要在前端把该数据转成json格式，
     * 即转成JSON.stringify(param)传进来
     * @Author:wrb
     * @Date:2020/1/10/17:25
     * @Param
     * @return com.baking.util.Msg
     */
    @RequestMapping(value = "/getProductList_v3")
    @ResponseBody
    public Msg getProductList_v3(@RequestBody Product product){
        System.out.println("getProductList_v3==>"+product);
        Msg msg = new Msg();
        List<Product> productList = productSerice.getProductList(product);
        msg.setCode("0");
        msg.setData(productList);
        return msg;
    }


    @RequestMapping("/downloadPage")
    public String toDowanloadPage(){

        return "/test/downloadPage";
    }


}
